﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SynergyCounts.DataContext;
using SynergyCounts.SelectionService;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace SynergyCounts
{
    sealed class Model : IModel
    {
        public IReadOnlyList<NavLink> GetSelectedNavLinks()
        {
            String selectionLinksPVID = null;

            BasicHttpBinding selectionServiceHttpBinding = new BasicHttpBinding();
            selectionServiceHttpBinding.Name = "SelectionServiceHttpBinding";
            selectionServiceHttpBinding.MaxBufferSize = 2147483647;
            selectionServiceHttpBinding.MaxReceivedMessageSize = 2147483647;
            selectionServiceHttpBinding.MaxBufferPoolSize = 2147483647;

            BasicHttpBinding dataServiceHttpBinding = new BasicHttpBinding();
            dataServiceHttpBinding.Name = "DataServiceHttpBinding";
            dataServiceHttpBinding.MaxBufferSize = 2147483647;
            dataServiceHttpBinding.MaxReceivedMessageSize = 2147483647;
            dataServiceHttpBinding.MaxBufferPoolSize = 2147483647;

            using (SelectionServiceClient selection = new SelectionServiceClient(selectionServiceHttpBinding, new EndpointAddress("http://localhost:8191/SelectionService")))
            {
                selectionLinksPVID = selection.getAtlasSelection();
            }

            using (DataServiceClient context = new DataServiceClient(dataServiceHttpBinding, new EndpointAddress("http://localhost:8191/DataService")))
            {
                return context.getNavLinksByLinkPvids(selectionLinksPVID);
            }
        }
    }
}
